package com.ywd.materials.admin.controller;

import com.ywd.materials.admin.common.Common;
import com.ywd.materials.admin.common.CommonGoodsType;
import com.ywd.materials.admin.dto.MaterialsGoodsTypeDto;
import com.ywd.materials.admin.dto.query.MaterialsGoodsTypeQuery;
import com.ywd.materials.admin.exception.R;
import com.ywd.materials.admin.exception.RPage;
import com.ywd.materials.admin.service.impl.MaterialsGoodsTypeServiceImpl;
import com.ywd.materials.admin.vo.MaterialsGoodsTypeVo;
import com.ywd.materials.admin.vo.MaterialsGoodsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lk
 * @date 2024/4/17 13:53
 */
@AllArgsConstructor
@RestController
@RequestMapping("/goodsType")
@Tag(name = "物资类型管理")
public class MaterialsGoodsTypeController {

    private final MaterialsGoodsTypeServiceImpl materialsGoodsTypeServiceImpl;

    @PostMapping("/saveGoodsType")
    @Operation(summary = "新增物资类型")
    public R<Boolean> saveGoodsType(@Validated @RequestBody MaterialsGoodsTypeDto dto) {
        return R.ok(materialsGoodsTypeServiceImpl.saveGoodsType(dto));
    }

    @PutMapping("/updateGoodsType")
    @Operation(summary = "修改物资类型")
    public R<Boolean> updateGoodsType(@Validated @RequestBody MaterialsGoodsTypeDto dto) {
        return R.ok(materialsGoodsTypeServiceImpl.updateGoodsType(dto));
    }

    @DeleteMapping("/deleteGoodsType")
    @Operation(summary = "删除物资类型")
    public R<Boolean> deleteGoodsType(@Schema(description = "ID") @RequestParam Long id) {
        return R.ok(materialsGoodsTypeServiceImpl.deleteGoodsType(id));
    }

    @PostMapping("/getGoodsTypePage")
    @Operation(summary = "查询物资类型列表(分页)")
    public R<RPage<List<MaterialsGoodsTypeVo>>> getGoodsTypePage(@RequestBody MaterialsGoodsTypeQuery query) {
        return R.ok(materialsGoodsTypeServiceImpl.getGoodsTypePage(query));
    }


    @GetMapping("/getGoodsTypeLevelList")
    @Operation(summary = "物资类型【层级】列表(筛选项)")
    public R<List<String>> getGoodsTypeLevelList(@Schema(description = "类型层级(1=一级, 2=二级, 3=三级)") @RequestParam(defaultValue = "1") Integer level,
                                                 @Schema(description = "名称") @RequestParam(required = false) String name) {
        return R.ok(materialsGoodsTypeServiceImpl.getGoodsTypeLevelList(level,name));
    }


    @GetMapping("/getGoodsTypePartList")
    @Operation(summary = "物资类型列表(筛选项)(平铺)")
    public R<List<Common>> getGoodsTypePartList(@Schema(description = "名称") @RequestParam(required = false) String name) {
        return R.ok(materialsGoodsTypeServiceImpl.getGoodsTypePartList(name));
    }


    @GetMapping("/getGoodsTypePartOneList")
    @Operation(summary = "物资类型列表(筛选项)(树形)")
    public R<List<CommonGoodsType>> getGoodsTypePartOneList() {
        return R.ok(materialsGoodsTypeServiceImpl.getGoodsTypePartOneList());
    }


}
